<?php
/**
 *  На входе GET
 * 
Array
(
    [start] => 0
    [limit] => 25
    [sort] => lastpost
    [dir] => DESC
    [_dc] => 1226077373311
    [callback] => stcCallback1001
)
*/
$news = loadmodule('news');
$news=new  news();
$newslist = $news->getAnons('main',intval($_GET['limit']), intval($_GET['start']), $_GET['sort'], $_GET['dir']);
$newscount = $news->count();
//print_pre($newslist);
# json для совмместимости с 4 php
include_once(engine.'/php4/json.php');


foreach ($newslist as $key=>$val) {
	$val['anons']=strip_tags($val['anons']);
	$newsout[$key]['id']=$val['id'];
	$newsout[$key]['title']=$val['title'];
	$newsout[$key]['date']=strtotime($val['date']);
	$newsout[$key]['text']=(strlen($val['anons']) >300)?(substr($val['anons'],0,600).'...'):$val['anons'];
}
// обнуляем если нет новостей
if ($newsout[0]['id']=='') $newsout='';

$out=$_GET['callback'].'({"totalCount":"'.$newscount.'","topics":'.json_encode($newsout).'});';
echo $out;
die();
//$file = loadclass('file',engine.'/log.txt');
//$file->setContent(print_r($_GET,true));
?>